package net.bbtang.website.utils;

import java.io.File;
import java.io.InputStream;

import com.aliyun.oss.OSSClient;

public class FileUtils {
	
	public static void uploadfile2oss(OSSConfigure configure,File uploadFile){
	    // endpoint以杭州为例，其它region请按实际情况填写
	    String endpoint = configure.getEndpoint();
	    // accessKey请登录https://ak-console.aliyun.com/#/查看
	    String accessKeyId = configure.getAccessKeyId();
	    String accessKeySecret = configure.getAccessKeySecret();
	   
	    OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
	    // 上传文件
	    
	    ossClient.putObject(configure.getBucketName(), uploadFile.getName(), uploadFile);
	    // 关闭client
	    ossClient.shutdown();
	} 
	
	public static void uploadfile2oss(OSSConfigure configure,String fileName,InputStream inputStream){
	    // endpoint以杭州为例，其它region请按实际情况填写
	    String endpoint = configure.getEndpoint();
	    // accessKey请登录https://ak-console.aliyun.com/#/查看
	    String accessKeyId = configure.getAccessKeyId();
	    String accessKeySecret = configure.getAccessKeySecret();
	   
	    OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
	    // 上传文件
	    ossClient.putObject(configure.getBucketName(), fileName, inputStream);
	    // 关闭client
	    ossClient.shutdown();
	} 
	
}
